<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <home></home>
    <news></news>
  </div>
  <script src="./vue.js"></script>
  <script>
    // 定义混入
    const mixin1 = {
      data(){
        return {
          msg: '这是一个公共的数据'
        }
      },
      methods: {
        changeMsg(){
          this.msg = this.msg.split('').reverse().join('')
        }
      },
      watch:{
        msg(){
          console.log('msg变化了')
        }
      }
    }
    const Home = {
      template:`
      <div>
        <h2>home组件 {{msg}}</h2>
        <button @click="changeMsg">按钮</button>

      </div>
      `,
      data(){
        return {
          msg: '我是自己的msg'
        }
      },
      mixins: [mixin1]
    }

    Vue.component('Home', Home)

    const News = {
      template:`
      <div>
        <h2>news组件</h2>
      </div>
      `
    }

    Vue.component('News', News)
    const vm = new Vue({
      el: "#app"
    })
  </script>
</body>
</html>